home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / gethdrs < prev    next >
Encoding:
Text File  |  1992-02-07  |  1.8 KB  |  66 lines

  1.  
  2. # This is a shell script version of gethdrs (the original was a trivial
  3. #  lex program).  This program extracts the names of the local (named
  4. #  using "name.h" instead of <name.h>) .h files included in source files.
  5. #  The major part of the work here is removing comments.  No consideration
  6. #  is given to the effects of preprocessor directives (e.g. #if - #endif
  7. #  blocks will not skip over #include lines) or strange things like
  8. #  "/*" appearing in a string literal.  I.e. the isolation of relevant
  9. #  #include directives is rather meager - but seems to be effective
  10. #  enough for now (the lack of handling of #if - #endif is annoying
  11. #  but tentative removal of include files seems to be done by commenting
  12. #  out).
  13. #
  14. # The script takes the source from standard input and writes to standard
  15. #  out.
  16. #
  17. # The script consists of a pipeline of two sed programs followed by
  18. #  a few shell commands.  The first sed program removes the comments
  19. #  (two sed programs were used because the finally decommented line
  20. #  could occur at two points and it was easier [if not necesary] to
  21. #  print the line right away, than to save it up for more processing),
  22. #  while the second isolates the included files' names and outputs them.
  23. #  The remainder puts all of these names onto one line with no terminating
  24. #  newline as wanted elsewhere (the program o2hdeps).
  25.  
  26. sed -n -e '
  27. : restart
  28. !c\
  29. Loop to remove contents of comment on single line leaving /**/-s
  30. : rm
  31. s+\(/\*\)[^*][^*]*+\1+g
  32. s+/\*\*\([^/]\)+/*\1+g
  33. t rm
  34. !c\
  35. Remove /**/-s then reset substitution-made flag
  36. s+/\*\*/+ +g
  37. t next
  38. : next
  39.  
  40. !c\
  41. On line containing start of comment block delete start of comment\
  42. and branch to remove remainder of block
  43. s+/\*\**++
  44. t delblk
  45. b aftrblk
  46. : delblk
  47. p
  48. : d2
  49. /\*\//!{
  50. n
  51. b d2
  52. }
  53. s+^+/*+
  54. b restart
  55.  
  56. :aftrblk
  57. p' | sed -n -e '
  58. /#include[     ]*"/{
  59. s/^[^"]*"//
  60. s/".*//
  61. p
  62. }' | while read hname
  63. do
  64. echo -n "$hname "
  65. done
  66.